import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home_A.vue'
// import First_B from '../views/First_B.vue'

Vue.use(VueRouter)
// 设置push和replace对同一个路由进行多次点击跳转
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      index: 0,
      log: 0,
      keep: 0,
      login:0
    }
  },
  {
    path: '/shopshop',
    name: 'Shopshop',
    component: () => import('../components/compoents_B/C_shopshop.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },
  {
    path: '/add',
    name: 'Add',
    component: () => import('../components/compoents_B/C_order_add.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },
  {
    path: '/pay',
    name: 'Pay',
    component: () => import('../components/compoents_B/C_pay.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },
  {
    path: '/address',
    name: 'Address',
    component: () => import('../components/compoents_B/C_address.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },

  {
    path: '/order',
    name: 'Order',
    component: () => import('../components/compoents_B/Order_B.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    },
  },
  {
 path:'/indent',
 name:'Indent',
 component:()=> import('../components/compoents_B/Indent_B.vue')
  },
  {
  path:'/indent_infor',
  name:'Indent_infor',
  component:()=> import('../components/compoents_B/Indent_infor_B.vue')
  },
  {
    path:'/add',
    name:'Add',
    component:()=> import('../components/compoents_B/C_order_add.vue')
      },
      {
    path:'/pay',
    name:'Pay',
    component:()=> import('../components/compoents_B/C_pay.vue')
      },
      {
        path:'/address',
        name:'Address',
        component:()=> import('../components/compoents_B/C_address.vue')
      },
     
  {
  path:'/order',
  name:'Order',
  component:()=> import('../components/compoents_B/Order_B.vue')
  },
  {
    path: '/fapiao',
    name: 'Fapiao',
    component: () => import('../components/compoents_B/C_fapiao.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },
  {
    path: '/first_B',
    name: 'First_B',
    component: () => import('../views/First_B.vue'),
    meta: {
      index: 1,
      log: 1,
      keep: 0,
      keeps:0,
      login:0,
    }
  },
  {
    path: '/other',
    name: 'Other',
    component: () => import('../components/compoents_B/C_other.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
    }
  },
  {
    path: '/shop_B',
    name: 'Shop_B',
    component: () => import('../views/Shop_B.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,
      title:"傻逼"
    }
  },
  {
    path: '/city/:id',
    name: 'City',
    component: () => import('../views/City_A.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/search_B',
    name: 'Search_B',
    component: () => import('../views/Serach_B.vue'),
    meta: {
      index: 1,
      log: 1, keep: 1,
      title:"搜索"
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../components/compoents_A/login_A.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/address_infor',
    name: 'Addinfor',
    component: () => import('../components/compoents_B/Address_infor_B.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Upload',
    name: 'Upload',
    component: () => import('../components/compoents_A/Upload.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
      title:"账户信息"
    }
  },
  {
    path: '/Mymoney',
    name: 'Mymoney',
    component: () => import('../components/compoents_A/Mymoney.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Mymonryspecific',
    name: 'Mymonryspecific',
    component: () => import('../components/compoents_A/Mymoneyspecific.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Mypreferential',
    name: 'Mypreferential',
    component: () => import('../components/compoents_A/Mypreferential.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Myintegral',
    name: 'Myintegral',
    component: () => import('../components/compoents_A/Myintegral.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Myintegralspecific',
    name: 'Myintegralspecific',
    component: () => import('../components/compoents_A/Myintegralspecific.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,
    }
  },
  {
    path: '/Ji_Afen',
    name: 'Ji_Afen',
    component: () => import('../components/compoents_A/Ji_Afen.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,titlt:"积分商城"
    }
  },
  // 我的会员卡的路由
  {
    path: '/Members',
    name: 'Members',
    component: () => import('../components/compoents_A/Members.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"会员中心"
    }
  },
  // 我的会员卡点进去会员中心
  {
    path: '/Members_said',
    name: 'Members_said',
    component: () => import('../components/compoents_A/Members_said.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"我的优惠"
    }
  },
  // 我的会员卡购买按钮
  {
    path: '/Buy',
    name: 'Buy',
    component: () => import('../components/compoents_A/Buy.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"支付中心"
    }
  },
  // 我的会员卡卡号密码
  {
    path: '/Cardnumber',
    name: 'Cardnumber',
    component: () => import('../components/compoents_A/Cardnumber.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"兑换会员"
    }
  },
  // 我的会员卡购买记录
  {
    path: '/Record',
    name: 'Record',
    component: () => import('../components/compoents_A/Record.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"购买记录"
    }
  },
  // 服务中心的路由
  {
    path: '/Service',
    name: 'Service',
    component: () => import('../components/compoents_A/Service.vue'),
    meta: {
      index: 0,
      log: 1, keep: 1,title:"服务中心"
    }
  },
  // 服务中心路由
  {
    path: '/ServiceCenter',
    name: 'ServiceCenter',
    component: () => import('../components/compoents_A/ServiceCenter.vue'),
    meta: {
      index: 0,
      log: 1,
      keep: 1,title:"详情"
    }
  },
  // 下载APP路由
  {
    path: '/Download',
    name: 'Download',
    component: () => import('../components/compoents_A/Download.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
      title:"下载"
    }
  },
  // 我的蓝色部分进去之后修改用户名
  {
    path: '/Account',
    name: 'Account',
    component: () => import('../components/compoents_A/Account.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的蓝色部分进去之后修改密码
  {
    path: '/Password',
    name: 'Password',
    component: () => import('../components/compoents_A/Password.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的优惠点击进去之后红包说明的路由
  {
    path: '/My_A_Btext_Cers',
    name: 'My_A_Btext_C',
    component: () => import('../components/compoents_A/My_A_Btext_C.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的优惠点击进去之后历史红包的路由
  {
    path: '/My_A_Bhistory_C',
    name: 'My_A_Bhistory_C',
    component: () => import('../components/compoents_A/My_A_Bhistory_C.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的优惠点击进去之后兑换红包的路由
  {
    path: '/My_A_Btab_Ch',
    name: 'My_A_Btab_Ch',
    component: () => import('../components/compoents_A/My_A_Btab_Ch.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的优惠点击进去之后兑换红包的路由
  {
    path: '/My_A_Btab_Ct',
    name: 'My_A_Btab_Ct',
    component: () => import('../components/compoents_A/My_A_Btab_Ct.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 我的优惠点击进去之后代金卷获取的数据路由
  {
    path: '/Myvouchers',
    name: 'Myvouchers',
    component: () => import('../components/compoents_A/Myvouchers.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  // 登录的路由
  {
    path: '/LoginWork',
    name: 'LoginWork',
    component: () => import('../views/LoginWork.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    }
  },
  {
    path: '/mine',
    name: 'Mine',
    component: () => import('../views/MineWork.vue'),
    meta: {
      index: 1,
      log: 1,
      keep: 1,
      title:"我的"
    }
  },
  {
    path: '/shopinfor',
    name: 'Shopinfor',
    component: () => import('../components/compoents_B/C_shopinfor.vue'),
    meta: {
      index: 0,
      log: 1,keep: 1,
    },
    children: [{
      path: '/evaluate',
      name: 'Evaluate',
      component: () => import('../components/compoents_B/Evaluate.vue'),
      meta: {
        index: 0,
        log: 1,keep: 1,
      }
    },
    {
      path: '/shangpin',
      name: 'Shangpin',
      component: () => import('../components/compoents_B/C_shopdetail.vue'),
      meta: {
        index: 0,
        log: 1,keep: 1,
        top:0
      }
    }
    ],
    redirect: { name: 'Shangpin' },
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

router.beforeEach(function(to,from,next){
  if(to.name != "Home" && to.name !="LoginWork"){
    if(localStorage.getItem('code1') == 200){
      next();
    }else{
      router.replace({name:'LoginWork'})
    }

  }
  else{
    next()
  }
 })

export default router
